/**
 * 腾讯地图API加载器
 * 用于动态加载腾讯地图API
 */
export function TMapLoader(key: string) {
  return new Promise(function (resolve, reject) {
    if ((window as any).TMap) {
      resolve((window as any).TMap);
      return;
    }
    const script = document.createElement("script");
    // 移除 model 库，基础加载
    script.src = `https://map.qq.com/api/gljs?v=1.exp&key=${key}&libraries=view,geometry,visualization,model`;
    script.async = true;
    script.onload = () => {
      if ((window as any).TMap) {
        resolve((window as any).TMap);
      } else {
        reject(new Error("TMap 加载失败"));
      }
    };
    document.body.appendChild(script);
  });
}

// 导出地图服务相关类
import { MapService } from './mapService';
import { ModelService } from './modelService';
import { InfoWindowService } from './infoWindowService';

// 导出加载模型相关函数
import { loadGLTFModel, destroyGLTFModel } from './loadGLTFModel';

// 导出模型数据相关
import { modelData, reloadModelData } from './example';

// 导出类型定义
import type { MapDataItem } from './extractModelData';
import type { InfoWindowColorConfig } from './infoWindowService';

export {
  // 服务类
  MapService,
  ModelService,
  InfoWindowService,
  
  // 模型加载函数
  loadGLTFModel,
  destroyGLTFModel,
  
  // 数据相关
  modelData,
  reloadModelData,
  
  // 类型定义
  type MapDataItem,
  type InfoWindowColorConfig
};
